// pages/my/getInspiration/index.js
const {
  myApi
} = require('../../../api/index')
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    IMGBASEURL: app.globalData.IMGBASEURL,
    userPhone: "",
    isShowBtn: false
  },
  inputChange(e) {
    this.setData({
      userPhone: e.detail.value
    })
  },
  getPacket() {
    wx.showLoading()
    myApi.isuserasync({
      PhoneNumber: this.data.userPhone
    }).then((res) => {
      console.log(res.StatusCode);
      if (res.StatusCode == 200) {
        if (res.Result) {
          myApi.scancodetosendvipacceptreward({
            Key: this.data.userPhone
          }).then((res) => {
            wx.hideLoading()
            if (res.StatusCode == 200) {
              this.setData({
                isShowBtn: true
              })
              wx.showToast({
                title: '领取成功',
                icon: 'none',
                duration: 2000
              })
            }else{
              wx.showToast({
                title: res.Message,
                icon: 'none',
                duration: 2000
              })
            }
          })
        } else {
          wx.hideLoading()
          wx.showModal({
            cancelText:'关闭',
            confirmText:'注册',
            title: '提示',
            content: '您的手机还未注册草图里，请先登录/注册再来领取吧。',
            complete: (res) => {
              if (res.confirm) {
                wx.navigateTo({
                  url: '/pages/login/index?backPageUrl=pages/my/getInspiration-gx/index'
                })
              }
            },
          })
        }
      } else {
        wx.showToast({
          title: res.Message,
          icon: 'none',
          duration: 2000
        })
      }
    }).catch(() => {
      wx.hideLoading()
      wx.showToast({
        title: '出错啦',
        icon: "error",
        duration: 2000
      })
    })
  },
  onLoad(options) {

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})